package com.itheima.controller;

import com.itheima.pojo.*;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    /*
     * 条件分页查询
     * 班级信息*/
    @GetMapping
    public Result page(QueryParam queryParam) {
        log.info("请求查询参数：QueryParam:{}", queryParam);
        PageResult pageResult = studentService.page(queryParam);
        return Result.success(pageResult);
    }

    /*
     * 3.4 根据ID查询学生接口*/
    @GetMapping("/{id}")
    public Result getStudentById(@PathVariable Integer id) {
        log.info("请求id:{}", id);
        Student student = studentService.getById(id);
        return Result.success(student);
    }

    /*
     *  新增学生信息接口
     * */
    @PostMapping
    public Result addStudent(@RequestBody Student student) {
        log.info("新增x学生，Student:{}", student);
        studentService.addStudent(student);
        return Result.success();
    }

    /*3.5 修改学生信息接口
    * */
    @PutMapping
    public Result updateStudent(@RequestBody Student student){
        log.info("更新Student:{}", student);
        studentService.update(student);
        return Result.success();
    }

    /*3.6 删除学生信息接口、
    批量删除
    * */
    @DeleteMapping("/{ids}")
    public Result deleteStudent(@PathVariable List<Integer> ids){
        log.info("要删除的学生ids:{}", ids);
        studentService.deleteByIds(ids);
        return Result.success();
    }

    /*
     该接口用于修改学员的
     违纪情况数据信息
     */
    @PutMapping("/violation/{id}/{score}")
    public Result updateViolationById(@PathVariable Integer id, @PathVariable Integer score){
        log.info("根据id修改学员的违纪情况：id:{},score:{}", id, score);
        studentService.updateViolationById(id,score);
        return Result.success();
    }
}
